import { createApp } from 'vue'
import App from './App.vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import './assets/style/index.scss'
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import 'virtual:svg-icons-register'
// 引入自定义插件对象：注册整个项目全局组件
import gloalComponent from '@/components'

import router from './router'
import pinia from './store'

router.beforeEach((to, from, next) => {
  // 设置标题
  // document.title = `${to.name}`
  // 获取token，判断是否登录
  const token = localStorage.getItem('token')
  console.log(token, 'token')
  if (to.path === '/login') return next()
  if (!token) {
    console.log('if')
    next('/login')
    return
  } else {
    console.log('else')

    next()
  }
})

const app = createApp(App)
app.use(ElementPlus, {
  locale: zhCn,
})
app.use(gloalComponent)

app.use(router)
app.use(pinia)
app.use(ElementPlus)
// 将应用挂载到挂载点上
app.mount('#app')
